<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Cookie;
use think\Session;

class User extends Controller
{
    //获取用户列表
    public function index()
    {
        if(Request::instance()->isAjax()){
            $page = input('get.page');
            $limit = input('get.limit');
            $page = empty($page)?1:$page;

            $count = Db::connect('user_db')->query("select count(*) as nums from s_member");
            $data['count'] = $count[0]['nums'];

            $sql = 'select * from s_member limit '.($page-1)*$limit.','.$limit;
            $res = Db::connect('user_db')->query($sql);

            $data['msg'] = '';
            $data['code'] = '';
            $data['data'] = $res;
            return $data;
        } else {
            return view('index');
        }
    }

    //获取管理员列表
    public function admin()
    {
        if(Request::instance()->isAjax()){
            $page = input('get.page');
            $limit = input('get.limit');
            $page = empty($page)?1:$page;

            $count = Db::connect('user_db')->query("select count(*) as nums from s_manage");
            $data['count'] = $count[0]['nums'];
            
            $sql = 'select * from s_manage limit '.($page-1)*$limit.','.$limit;
            $res = Db::connect('user_db')->query($sql);

            $data['msg'] = '';
            $data['code'] = '';
            $data['data'] = $res;
            return $data;
        } else {
            return view('admin');
        }
    }

    //获取角色列表
    public function role()
    {
        return view('role');
    }


    //查看用户详情
    public function viewuser()
    {
        if(Request::instance()->isAjax()){
            $uid = input('get.uid');

            $count = Db::connect('user_db')->query("select count(*) as nums from s_down_a where uid=".(int)$uid);
            $data['ad'] = $count[0]['nums'];

            $count = Db::connect('user_db')->query("select count(*) as nums from s_down_a where uid=".(int)$uid." and downtime>=".strtotime(date('Y-m-d',time())));
            $data['cd'] = $count[0]['nums'];

            $data['msg'] = '';
            $data['code'] = '';
            return $data;
        }
    }

}